package com.yanqu.road.entity.activity.climbtower.enums;

public enum  eClimbTowerCellType {

    ONE(1, "三等分", 3),

    TWO(2, "单通道", 1),

    THREE(3, "两通道-右合", 2),

    FOUR(4, "两通道-左合", 2),

    FIVE(5, "二等分", 2)
    ;

    int type;

    String desc;

    int eventNum;

    /**
     * 获取格子左边界
     * @param index 格子索引(从0开始）
     * @return
     */
    public float getCellRightBoundary(int index){
        if(this == ONE){
            return index + 1;
        }
        if(this == TWO){
            return 3;
        }
        if(this == THREE){
            if(index > 0){
                return 3;
            }
            return 1;
        }
        if(this == FOUR){
            if(index > 0){
                return 3;
            }
            return 2;
        }
        if(this == FIVE){
            if(index == 0){
                return 1.5f;
            }
            return 3;
        }
        return 0;
    }

    /**
     * 获取格子右边界
     * @param index 格子索引(从0开始）
     * @return
     */
    public float getCellLeftBoundary(int index){
        if(this == ONE){
            return index;
        }
        if(this == TWO){
            return 0;
        }
        if(this == THREE){
            if(index > 0){
                return 1;
            }
            return 0;
        }
        if(this == FOUR){
            if(index > 0){
                return 2;
            }
            return 0;
        }
        if(this == FIVE){
            if(index == 0){
                return 0;
            }
            return 1.5f;
        }
        return 0;
    }

    /**
     * 格子是否连同
     * @param curType 当前类型
     * @param index  当前格子索引
     * @param nextType 下一个类型
     * @param nextIndex 下一个格子索引
     * @return
     */
    public static boolean isConnected(eClimbTowerCellType curType, int index, eClimbTowerCellType nextType, int nextIndex){
        boolean connect = true;

        if(curType.getCellLeftBoundary(index) >= nextType.getCellRightBoundary(nextIndex)){
            connect = false;
        }

        if(curType.getCellRightBoundary(index) <= nextType.getCellLeftBoundary(nextIndex)){
            connect = false;
        }

        return connect;
    }

    eClimbTowerCellType(int type, String desc, int eventNum) {
        this.type = type;
        this.desc = desc;
        this.eventNum = eventNum;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getEventNum() {
        return eventNum;
    }

    public void setEventNum(int eventNum) {
        this.eventNum = eventNum;
    }

    public static int getEventNum(int cellType){
        for (eClimbTowerCellType value : eClimbTowerCellType.values()) {
            if(value.getType() == cellType){
                return value.eventNum;
            }
        }
        return 0;
    }

    public static eClimbTowerCellType getCellType(int cellType){
        for (eClimbTowerCellType value : eClimbTowerCellType.values()) {
            if(value.getType() == cellType){
                return value;
            }
        }
        return null;
    }
}
